/*
XBaseTools
Copyright (C) 2008 Matthew Perry

This library/program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This libary/program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;

namespace BaseTools.Strings
{
	/// <summary>
	/// A string block
	/// </summary>
	public struct StringBlock : IEquatable<StringBlock>
	{
		/// <summary>
		/// String block data
		/// </summary>
		public string Data;
		
		/// <summary>
		/// String block is quoted
		/// </summary>
		public bool Quoted;
		
		/// <summary>
		/// Creates a new string block
		/// </summary>
		/// <param name="Data"></param>
		/// <param name="Quoted"></param>
		public StringBlock(string Data, bool Quoted)
		{
			this.Data = Data;
			this.Quoted = Quoted;
		}
		
		#region Equals and GetHashCode implementation
		// The code in this region is useful if you want to use this structure in collections.
		// If you don't need it, you can just remove the region and the ": IEquatable<StringBlock>" declaration.
		
		/// <summary>
		/// Equals
		/// </summary>
		/// <param name="obj"></param>
		/// <returns></returns>
		public override bool Equals(object obj)
		{
			if (obj is StringBlock)
				return Equals((StringBlock)obj); // use Equals method below
			else
				return false;
		}
		
		/// <summary>
		/// Equals
		/// </summary>
		/// <param name="other"></param>
		/// <returns></returns>
		public bool Equals(StringBlock other)
		{
			// add comparisions for all members here
			return this.Data == other.Data && this.Quoted == other.Quoted;
		}
		
		/// <summary>
		/// Xor'ed hash codes
		/// </summary>
		/// <returns></returns>
		public override int GetHashCode()
		{
			// combine the hash codes of all members here (e.g. with XOR operator ^)
			return Data.GetHashCode() ^ Quoted.GetHashCode();
		}
		
		/// <summary>
		/// Equals operator
		/// </summary>
		/// <param name="lhs"></param>
		/// <param name="rhs"></param>
		/// <returns></returns>
		public static bool operator ==(StringBlock lhs, StringBlock rhs)
		{
			return lhs.Equals(rhs);
		}
		
		/// <summary>
		/// Inequal operator
		/// </summary>
		/// <param name="lhs"></param>
		/// <param name="rhs"></param>
		/// <returns></returns>
		public static bool operator !=(StringBlock lhs, StringBlock rhs)
		{
			return !(lhs.Equals(rhs)); // use operator == and negate result
		}
		#endregion
	}
}
